home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / modprolg / mod-prol.lha / Prolog / modlib / src / $call.P < prev    next >
Encoding:
Text File  |  1992-05-01  |  4.5 KB  |  125 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25. /****************************************************************************
  26.  *                                                                          *
  27.  * This file has been changed by to include Modules Extensions              *
  28.  * Changes by : Brian Paxton 1991/92                                        *
  29.  * Last update : June 1992                                                  *
  30.  *                                                                          *
  31.  * Organisation : University of Edinburgh.                                  *
  32.  * For : Departments of Computer Science and Artificial Intelligence        * 
  33.  *       Fourth Year Project.                                               *
  34.  *                                                                          *
  35.  ****************************************************************************/
  36.  
  37. /* $call.P */
  38.  
  39. $call_export([call/1,'_$interp'/2,'_$call'/1,call/2]).
  40.  
  41. % $call_use : $modules
  42.  
  43. '_$interp'(','(A,B),CP) :- !,'_$interp'(A,CP),'_$interp'(B,CP).
  44.  
  45. '_$interp'(';'(A,B),CP) :- !,'_$interpor'(A,CP,B).
  46.  
  47. '_$interp'('!',CP) :- '_$cutto'(CP).
  48.  
  49. '_$interp'('->'(A,B),CP) :- !,
  50.     '_$savecp'(NCP),'_$interp'(A,NCP),!,'_$interp'(B,CP).
  51.  
  52. '_$interp'([H|L], _) :- !, $consult_list([H|L]).
  53. '_$interp'(Goal,_) :- '_$builtin'(10).    /* '_$call'(Goal) */
  54.  
  55. '_$interpor'('->'(Bool,Then),CP,Else) :- 
  56.     !,'_$interpif'(Bool,CP,Else,Then).
  57. '_$interpor'(A,CP,_) :- '_$interp'(A,CP).
  58. '_$interpor'(_,CP,B) :- '_$interp'(B,CP).
  59.  
  60. '_$interpif'(Bool,CP,Else,Then) :- 
  61.     '_$savecp'(NCP),'_$interp'(Bool,NCP),!,'_$interp'(Then,CP).
  62. '_$interpif'(_,CP,Else,_) :- '_$interp'(Else,CP).
  63.  
  64.  
  65. '_$call'([H|L]) :- !, $consult_list([H|L]).
  66. '_$call'(X) :- '_$builtin'(10).
  67.  
  68. (A,B) :- '_$call'(A),'_$call'(B).
  69.  
  70. ','(A,B,C,D) :- '_$call'(A),'_$call'(B),'_$call'(C),'_$call'(D).
  71.  
  72. /*
  73. (A->B;C) :- !,(call(A) -> '_$call'(B) ; '_$call'(C)).
  74. (A;B) :- '_$call'(A).
  75. (A;B) :- '_$call'(B).
  76. */
  77.  
  78. ';'(A, B) :-
  79.     A = (Test -> Then) ->
  80.         (call(Test) -> '_$call'(Then) ; '_$call'(B)) ;
  81.     ('_$call'(A) ; '_$call'(B)).
  82.  
  83.  
  84. (A->B) :- call(A) -> '_$call'(B).
  85.  
  86. not(A) :- call(A) -> fail ; true.
  87.  
  88. '\+'(A) :- call(A) -> fail ; true.
  89.  
  90. % call/1 is unaffected by the modules system.
  91.  
  92. call(X) :- '_$savecp'(C),'_$interp'(X,C).
  93.  
  94. % call/2 used to call predicates in remote structures. The call to 
  95. % $expand_body/2 ensures that predicates like name/2 are converted into
  96. % their correct form name/3, etc. The call to $move_clause/4 physically
  97. % alters the tags within the call to the destination structure tag. Note
  98. % that the call itself can only contain references to one structure only (ie.
  99. % it cannot refer to any substructures from the current structure).
  100.  
  101. call(X,Str) :-
  102.     ( $isa_structuretag(Str) ->
  103.         ( Str == perv -> call(X) ;
  104.             ( $call_oldtag(X,Oldtag),
  105.               $expand_body(X,X0,Str),
  106.               $move_clause(X0,Oldtag,Str,Y),
  107.               call(Y) ) ) ;
  108.         ( $telling(Tell), $tell(user),
  109.           $writename('*** Error : Second arg to call/2 must be structure tag'),
  110.           $nl, $tell(Tell), fail ) ).
  111.  
  112. % $call_oldtag/2 grabs the tag at the head of the call (or tag of the first
  113. % call if there are several), and all other tags in the call have to be
  114. % equal to this one.
  115.  
  116. $call_oldtag((X, _), Tag) :- !,
  117.     $call_oldtag(X, Tag).
  118. $call_oldtag((X; _), Tag) :- !,
  119.     $call_oldtag(X, Tag).
  120. $call_oldtag((X -> _), Tag) :- 1,
  121.     $call_oldtag(X, Tag).
  122. $call_oldtag(X, Tag) :-
  123.     $functor0(X, Name),
  124.     $dismantle_name(Name, _, Tag).
  125.